//
//  SchoolListViewController.m
//  edu
//
//  Created by baobaodp on 13-8-29.
//  Copyright (c) 2013年 baobaodp. All rights reserved.
//

#import "SchoolListViewController.h"
#import "SchoolListCell.h"
#import "SchoolRecruitInfoViewController.h"
#import "Record.h"
#import "DBbase.h"
#import "EduViewController.h"

@interface SchoolListViewController ()

@end

@implementation SchoolListViewController

@synthesize m_record;


-(id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];
    if (self) {
        // Custom initialization
        self.isWithSearchBar = TRUE;
    }
    return self;
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark -
#pragma mark Table Data Source Methods
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSUInteger row = [indexPath row];
    if(row < self.datas.count){
    
        Record *data = [self.datas objectAtIndex:row];
        NSLog(@"%d",[[data getFieldValueByName:@"schCount"] intValue]);
        return 184 + [[data getFieldValueByName:@"schCount"] intValue] * 64;
    }
    
    
    
    return 50;
}
- (NSInteger)tableView:(UITableView *)tableView
 numberOfRowsInSection:(NSInteger)section
{
    [self getRecords];
    return [self.datas count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"SchoolListCellIdentifier";
    
    SchoolListCell *cell = (SchoolListCell *)[tableView
                                                  dequeueReusableCellWithIdentifier: cellIdentifier];
    if (cell == nil)
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"SchoolListCell"
                                                     owner:self options:nil];
        for (id oneObject in nib)
            if ([oneObject isKindOfClass:[SchoolListCell class]])
                cell = (SchoolListCell *)oneObject;
    }
	
    //[self configureCell:cell indexPath:indexPath accessoryType:DISCLOSURE_INDICATOR];
    
    NSUInteger row = [indexPath row];
    [cell setData:[self.datas objectAtIndex:row] index:row];
    
    //------cell背景透明化--------------------------------------------
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.backgroundColor = [UIColor clearColor];
    cell.contentView.backgroundColor = [UIColor clearColor];
    UIView *backView = [[UIView alloc] initWithFrame:CGRectZero];
    backView.backgroundColor = [UIColor clearColor];
    cell.backgroundView = backView;
    //--------------------------------------------------
    
    return cell;
}


#pragma mark -
#pragma mark Table view delegate
//
//- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//    // Navigation logic may go here. Create and push another view controller.
//	
//	SchoolRecruitInfoViewController *detailViewController = [[SchoolRecruitInfoViewController alloc] initWithNibName:@"SchoolRecruitInfoViewController" bundle:nil];
//    
//	
//	if (tableView == self.searchDisplayController.searchResultsTableView){
//        //		detailViewController.currentLineName = [filteredListContent objectAtIndex:indexPath.row];
//        //		detailViewController.currentLineIndex = [[CDataContainer Instance].lineNameArray indexOfObject:[filteredListContent objectAtIndex:indexPath.row]];
//	}
//	else{
//        //		detailViewController.currentLineName = [[CDataContainer Instance].lineNameArray objectAtIndex:indexPath.row];
//        //		detailViewController.currentLineIndex = indexPath.row;
//	}
//    
//    NSUInteger row = [indexPath row];
//    [detailViewController setData:[self.datas objectAtIndex:row] index:row];
//
//	[self.navigationController pushViewController:detailViewController animated:YES];
//    
//}

- (void) setData:(Record *) record index: (int) rowIndex
{
    self.m_record= record;
}

-(void)getRecords
{
    NSString *querySql = [NSString stringWithFormat:@"select T2.sch_Id,T2.sch_Name ,count(T2.sch_Id) as schCount from T_Souce T1 left join M_School T2 on T1.sch_Id = T2.sch_Id where T2.schLv_Div= '%@' group by T2.sch_Id,T2.sch_Name order by T2.sch_Id" ,[m_record getFieldValueByName:@"div"]];
    
    const char *sql = [querySql UTF8String];
    
    self.datas = getDbRecords(sql,@"T_Souce",[NSArray arrayWithObjects:@"soucd_Id", nil]);
}
@end
